package com.personalforumapi.repository;

import com.personalforumapi.entity.comment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * @Author:kinjaze
 * @Date:2020/9/24 10:50
 */
public interface commentRepostitory extends JpaRepository<comment,Integer> {
    //自定义查询语句
    @Query(value = "select * from comment where aid = :aid", nativeQuery = true)
    List<comment> findByAid(@Param("aid") Integer aid);

    @Transactional//支持事务管理
    @Modifying(clearAutomatically = true)//表示执行增、删、改操作，clearAutomatically = true 表示清理实体类里的数据。
    @Query(value = "UPDATE comment SET cagree = :agree WHERE aid = :aid and cid=:cid", nativeQuery = true)
    void updateByAid(@Param("aid") Integer aid, @Param("agree") Integer agree,@Param("cid") Integer cid);
}
